<?php

use Illuminate\Support\Facades\Route;
use App\Entity\Member;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});
// get/post/any/match四种请求格式 
Route::get('get',function(){
    echo '我是get请求';
});
Route::post('post',function(){
    echo '我是post请求';
});
Route::any('any',function(){
    echo '我是any请求';
});
Route::match(['get','post'],'match',function(){
    echo '我是match请求';
});

// 路由参数
// 必选参数{id},不填报404
Route::any('/user/{id}',function($id){
    echo '当前用户id为'.$id;
});
// 可选参数{id?},报500原因是function没有给默认值
Route::any('/pepole/{id?}',function($id=''){
    // echo gettype($id).'</br>';
    // echo var_dump($id).'</br>';
    // echo $id=='';
    if($id==''){
        echo '用户没有输入id';
    }else{
        echo '当前用户id为'.$id;
    }
});
// 通过问号(?)传参
Route::any('/user2',function(){
    echo '当前用户id为'.$_GET['id'];
});

// 路由别名(路由地址别名)
Route::any('/test1/test20/test3/test4',function(){
    echo '路由别名(路由地址别名)';
})->name('alias');

// 查看系统所有路由命令
// php artisan routeL:list

// 路由群组
Route::group(['prefix'=>'admin'],function(){
    Route::get('login',function(){
        echo 'login页面';
    });
    Route::get('loginout',function(){
        echo 'loginout页面';
    });
    Route::get('index',function(){
        echo 'index页面';
    });

});

// 定义增删盖查db路由
Route::group(['prefix'=>'home'],function(){
    Route::get('add','TestController@add');
    Route::get('del','TestController@del');
    Route::get('update','TestController@update');
    Route::get('select','TestController@select');
    Route::get('input','TestController@input');
});

// 定义测试路由（模型的增删改查）
Route::group(['prefix'=>"home"],function(){
    Route::get('test1','TestController@test1');
    Route::get('test2','TestController@test2');
    Route::get('test3','TestController@test3');
    Route::get('test4','TestController@test4');
});
// 自动校验
Route::any('home/login','TestController@login');

// 文件上传
Route::any('home/test5','TestController@test5');
// sql查询操作
Route::any('home/test6','TestController@test6');

Route::get('member',function(){
    return Member::all();
});